package com.iweb.web.servlet;

import com.iweb.commons.utils.BeanUtil;
import com.iweb.commons.utils.ModelAndView;
import com.iweb.commons.utils.UrlUtil;
import com.iweb.web.controller.FoodController;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author: jack
 * @date: 2022-08-05 0005
 * @ApiNOTE:
 */
@WebServlet(value = "/food/*", loadOnStartup = 1)
public class FoodServlet extends HttpServlet {

  @Override
  protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String action = UrlUtil.action(req, "/food/");
    if ("list".equals(action)) {
      findAllFood(req, resp);
    }

  }

  private void findAllFood(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    FoodController foodController = BeanUtil.getBean(getServletContext(), "food");
    ModelAndView mv = foodController.findAllFood();
    mv.render(req, resp, mv);
  }
}
